package com.example.experiment_4;

import android.content.Context;
import android.content.SharedPreferences;
import android.widget.Toast;

public class SPSaveLogin {

    public static void saveUserInfo(String account, String password, Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        sharedPreferences
                .edit()
                .putString("account", account)
                .putString("password", password)
                .apply();
        Toast.makeText(context, "注册成功!", Toast.LENGTH_SHORT).show();
    }

    public static void login(String account, String password, Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        String storageAccount = sharedPreferences.getString("account", "");
        String storagePassword = sharedPreferences.getString("password", "");

        if (account.equals(storageAccount) && password.equals(storagePassword)) {
            Toast.makeText(context, "登录成功!", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(context, "登录失败!", Toast.LENGTH_SHORT).show();
        }
    }

}
